<?php

declare(strict_types=1);

namespace app\model;

use think\Model;
use think\facade\Db;

/**
 * @mixin \think\Model
 */
class Config extends Model
{
    //保存设置
    public static function saves($data)
    {
        $config = $data['config'];
        unset($data['config']);
        foreach ($data as $k => $v) {
            $find = Db::name('config')->where('name', $k)->where('inc_type', $config)->find();
            if ($find) {
                Db::name('config')->where('name', $k)->where('inc_type', $config)->update(['value' => $v, 'rep_date' => time()]);
            } else {
                Db::name('config')->insert(['name' => $k, 'value' => $v, 'inc_type' => $config, 'rep_date' => time()]);
            }
        }
    }

    //查询设置
    public static function list($name)
    {
        $res = Db::name('config')->where('inc_type', $name)->select();
        return $res;
    }
}
